﻿using AutoMapper;
using MediatR;
using T_vehicle.API.Application.Command.MaintenanceCommand;
using T_vehicle.Domain;
using T_vehicle.Infrastructure.Interfacec;

namespace T_vehicle.API.Application.CommandHandlers.MaintenanceCommandHandlers
{
    public class AddMaintenanceCommandHandlers:IRequestHandler<AddMaintenanceCommand,int>
    {
        private readonly IMaintenanceRepository maintenanceRepository;
        private readonly IMapper mapper;

        public AddMaintenanceCommandHandlers(IMaintenanceRepository maintenanceRepository, IMapper mapper)
        {
            this.maintenanceRepository = maintenanceRepository;
            this.mapper = mapper;
        }

        public async Task<int> Handle(AddMaintenanceCommand request, CancellationToken cancellationToken)
        {

            var info = mapper.Map<Maintenance>(request);
            return await maintenanceRepository.AddAsync(info);

            //var info = new Maintenance();
            //info.MaintenanceTitle= request.MaintenanceTitle;
            //info.LicenNumber= request.LicenNumber;
            //info.MaintenanceMoney= request.MaintenanceMoney;
            //info.Head=info.Head;
            //info.MaintenanceDateNow= request.MaintenanceDateNow;
            //info.MaintenanceDate=request.MaintenanceDate;
            //info.Mileage =request.Mileage;
            //info.MaintenanceMileage=request.MaintenanceMileage;
            //info.Remark=request.Remark;
            //info.Project=request.Project;
            //return await maintenanceRepository.AddAsync(info);

        }
    }
}
